<template>
  <div>
    <el-col :span="24" class="bg1">
      <div class="grid-content bg-purple">
        <FormPanel ref="formPanel" :list="formList" :cols="3" :labelWidth="110" :isSubmitBtn="false" @formChange="changeHandle" />
      </div>
    </el-col>

    <div class="dialogBottmView">
      <multiuse-button type="primary" class="btnStyle" :click="closeMenu.bind(this, 1)">确认修改</multiuse-button>

      <multiuse-button type="primary" class="btnStyle" :click="closeMenu.bind(this, 2)">关闭</multiuse-button>
    </div>

    <BaseDialog :visible.sync="visible" title="经销商信息查询" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }" destroyOnClose>
      <add-delear @selectArr="selectFun" @close="closeDialog"></add-delear>
    </BaseDialog>
  </div>
</template>

<script>
import { dealerMixin } from '@/pages/repair/batchEventManagement/dealerMixin';

import { editResDealer } from '@/api/repair/batchEventManagement/carStatusAndDealer';
import { dictionary } from '@/utils/dictMixin';
import { isEmpty } from '@/utils/utils';
import { exportExcelFile } from '@/utils/index';
import { arrayObjDeWeight } from '@/utils';
import addDelear from './addDelear';

export default {
  name: 'add',
  mixins: [dictionary, dealerMixin],
  /*handleType add 新增  edit  编辑*/
  props: ['handleType', 'maId', 'formData'],
  data() {
    this.saveData = null;
    return {
      formList: this.createFormList(),
      visible: false,

      onChangeColumn: [],

      detailObj: {},
      /*是否可下发*/
      isClicked: false,
      resDealer: ''
    };
  },
  components: {
    addDelear
  },
  mounted() {
    this.getAllDelears(this.formList, ['oldResDealer'], 'form');
    // this.getAllDelears(this.formList, 'oldResDealer', 'table')

    this.getData();
  },
  methods: {
    closeDialog() {
      console.log('关闭');
      this.visible = false;
    },
    selectFun(arr) {
      let row = arr[0];
      this.resDealer = row['dealerCode'];

      this.formList.find(item => item.fieldName == 'resDealer').initialValue = row['dealerName'];
      console.log(arr);
    },

    /*根据ID查询*/
    async getData() {
      let data = isEmpty(this.formData) ? {} : this.formData;

      // if (10041001 == ifPart && 10041001 == ifTech && 10041001 == ifClaim)
      // {
      //   this.isClicked = true
      // } else
      // {
      //   this.isClicked = false
      // }

      for (let i in data) {
        this.formList.map(x => {
          if (i == x.fieldName) {
            x.initialValue = data[i];
          }
        });
      }
      this.formList.find(item => item.fieldName == 'oldVinStatus').initialValue = data['vinStatus'];
      this.formList.find(item => item.fieldName == 'oldResDealer').initialValue = data['resDealer'];
      this.formList.find(item => item.fieldName == 'resDealer').initialValue = '';
      this.formList.find(item => item.fieldName == 'vinStatus').initialValue = '';
    },

    async closeMenu(type) {
      if (type == '1') {
        /*保存数据*/
        this.$refs.formPanel.SUBMIT_FORM();

        let obj = this.saveData;

        let resDealer = isEmpty(obj['resDealer']) ? '' : this.resDealer;
        let vinStatus = isEmpty(obj['vinStatus']) ? '' : obj['vinStatus'];

        if (isEmpty(resDealer) && isEmpty(vinStatus)) {
          this.$notify.warning({ title: '提示信息', message: '最新责任经销商与最新车辆状态不能同时为空' });
          return;
        }

        let params = {
          vinStatus: vinStatus,
          resDealer: resDealer,
          remarks: obj['remarks'],
          maId: this.formData['maId'],
          areaId: this.formData['areaId']
        };

        let res = await editResDealer(params);

        if (res.resultCode == 200 && res.success == true) {
          this.$emit('close', 'refresh');
        } else {
          // let errMsg = isEmpty(res.errMsg) ? '操作失败' : res.errMsg;
          //
          // this.$notify.error({title: '提示信息', message: errMsg});
        }
      } else {
        this.$emit('close');
      }
    },
    closeDialog() {
      this.visible = false;
    },

    seacherFun() {
      this.visible = true;
    },

    changeHandle(val) {
      this.saveData = val;
    },
    createFormList() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '批量活动基本信息'
        },
        {
          type: 'INPUT',
          label: '活动编号',
          fieldName: 'maNo',
          itemList: [],
          disabled: true,
          placeholder: '',
          // rules: [{required: true, trigger: 'change'}],
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '活动主题',
          fieldName: 'maTitle',
          disabled: true,
          rules: [{ required: false, trigger: 'change' }],
          placeholder: '请输入',
          initialValue: ''
        },
        {
          type: 'DATE',
          label: '活动开始日期',
          fieldName: 'bDate',
          disabled: true,
          format: 'yyyy-MM-dd',
          placeholder: '请选择',
          rules: [{ required: false, trigger: 'change' }],
          initialValue: ''
        },

        {
          type: 'DATE',
          label: '活动截止日期',
          fieldName: 'eDate',
          disabled: true,
          format: 'yyyy-MM-dd',
          placeholder: '请选择',
          rules: [{ required: false, trigger: 'change' }],
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '活动等级',
          fieldName: 'maLevel',
          placeholder: '',
          initialValue: '',
          disabled: true,
          rules: [{ required: false, trigger: 'change' }],
          itemList: this.createDictList(1017)
        },
        {
          type: 'INPUT',
          label: '主损件代码',
          fieldName: 'partCode',
          placeholder: '请选择',
          readonly: true,
          disabled: true,
          initialValue: ''
          // unitRender: () =>
          // {
          //   return (
          //     <div>
          //       <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
          //     </div>
          //   );
          // },
        },
        {
          type: 'INPUT',
          label: '主损件名称',
          fieldName: 'partName',
          placeholder: '请选择',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '是否OTA活动',
          fieldName: 'ifOta',
          placeholder: '',
          initialValue: '',
          disabled: true,
          rules: [{ required: false, trigger: 'change' }],
          itemList: this.createDictList(1004)
        },

        {
          type: 'TEXT_AREA',
          label: '活动说明',
          fieldName: 'maRemarks',
          placeholder: '请选择',
          disabled: true,
          rules: [{ required: false, trigger: 'change' }],
          initialValue: '',
          selfCols: 3
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请选择',
          disabled: true,
          rules: [{ required: false, trigger: 'change' }],
          initialValue: ''
        },
        {
          type: 'DATE',
          label: '活动下发日期',
          fieldName: 'maDate',
          placeholder: '',
          disabled: true,
          format: 'yyyy-MM-dd',
          initialValue: '请选择',
          rules: [{ required: false, trigger: 'change' }]
        },
        {
          type: 'DATE',
          label: '考核截止日期',
          fieldName: 'verifyDate',
          placeholder: '',
          disabled: true,
          format: 'yyyy-MM-dd',
          initialValue: '请选择',
          rules: [{ required: false, trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '原责任经销商',
          fieldName: 'oldResDealer',
          placeholder: '',
          initialValue: '',
          disabled: true,
          itemList: [],
          rules: [{ required: false, trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '原车辆状态',
          fieldName: 'oldVinStatus',
          placeholder: '',
          disabled: true,
          initialValue: '',
          rules: [{ required: false, trigger: 'change' }],
          itemList: this.createDictList(6040)
        },
        {
          type: 'INPUT',
          label: '最新责任经销商',
          fieldName: 'resDealer',
          placeholder: '请选择',
          readonly: false,
          rules: [{ required: true, message: '最新责任经销商不能为空', trigger: 'change' }],
          initialValue: '',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
              </div>
            );
          }
        },
        {
          type: 'SELECT',
          label: '最新车辆状态',
          fieldName: 'vinStatus',
          placeholder: '',
          initialValue: '',
          disabled: false,
          rules: [{ required: true, message: '最新车辆状态不能为空', trigger: 'change', message: '请选择' }],
          itemList: this.createDictList(6040)
        },

        {
          type: 'TEXT_AREA',
          label: '修改说明',
          fieldName: 'remarks',
          placeholder: '请选择',
          rules: [{ required: false, trigger: 'change' }],
          initialValue: '',
          selfCols: 3,
          maxlength: 300
        }
      ];
    }
  }
};
</script>

<style scoped lang="less">
.bg1 {
  border: 1px solid @borderColor;
  border-radius: @borderRadius;
  box-shadow: @boxShadow;
  padding: @modulePadding;
  padding-left: 0;
  padding-top: 15px;
  padding-bottom: 15px;
}

.bg2 {
  margin-top: 10px;
  margin-bottom: 10px;
}

.btn {
  text-align: center;
}

.btnStyle {
  margin-top: 10px;
}
</style>
